package edu.umn.msse.farside.FourH.web;

import edu.umn.msse.farside.FourH.domain.Position;
import edu.umn.msse.farside.FourH.domain.Volunteer;
import edu.umn.msse.farside.FourH.services.EventService;
import edu.umn.msse.farside.FourH.services.VolunteerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * User: Farside
 * Date: Mar 23, 2009
 * To change this template use File | Settings | File Templates.
 */
@Controller
@RequestMapping("/removeVolunteer")
public class RemoveVolunteerController
{
    private EventService eventService;
    private VolunteerService volunteerService;

    @Autowired
    public void setEventService(EventService eventService)
    {
        this.eventService = eventService;
    }

    @Autowired
    public void setVolunteerService(VolunteerService volunteerService)
    {
        this.volunteerService = volunteerService;
    }

    @RequestMapping(method = {RequestMethod.GET, RequestMethod.POST})
    public String removeVolunteer(@RequestParam(required=true) Long volunteerID, @RequestParam(required=true) Long positionID, @RequestParam(required=true) Long eventID)
    {
        Volunteer volunteer = volunteerService.getVolunteer(volunteerID);

        Position position = eventService.getPosition(positionID);

        position.removeVolunteer(volunteer);
        eventService.updatePosition(position);

        return "redirect:editPosition?eventID=" + eventID + "&positionID="+positionID;
    }
}
